<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="编辑商品">
    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">
    <script type="text/javascript" src="${baseUrl}js/myGoods.js"></script>
    <style type="text/css">
        #goods-img{
            background-color:#eeeeee;border: 4px solid #eeeeee; border-radius: 4px;width: 160px;height: 160px;
        }

        .deleteSecondUnit{
            cursor: pointer;
        }
    </style>
    <script>


        jQuery(function () {
            init();
        });
    </script>
</html:header>
<body>

<div style="display: none">
    <form enctype="multipart/form-data">
        <input type="file" id="image-file" name="imageFile"/>
    </form>
</div>

<div style="height: 40px;">
    <div class="mb4" style="position: fixed;top: 10px;right: 20px;z-index: 99999999;">
        <a class="layui-btn save">保存</a>
        <a class="layui-btn layui-btn-primary closeSelf" href="javascript:;">取消</a>
    </div>
</div>

<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form" method="post" action="" lay-filter="goodsForm">
            <button id="submit" class="layui-btn" lay-submit="" lay-filter="goods" style="display: none;"></button>
            <input type="hidden" name="oper" value="update">
            <input type="hidden" name="unitCount" value="1">
            <input type="hidden" name="attrNameCount" value="${fn:length(attrNameVoList)}">
            <input type="hidden" name="id" value="${id}">
            <%--是否被单据引用--%>
            <input type="hidden" name="used" value="${used}">
            <input type="hidden" name="usedByPacket" value="${usedByPacket}">

            <input type="hidden" name="houseCount" value="${fn:length(houseVoList)}">
            <c:forEach items="${houseVoList}" var="houseVo" varStatus="status">
                <input type="hidden" name="houseId${status.index}" value="${houseVo.id}">
            </c:forEach>
            <data id="data"></data>


            <h3>图片</h3>
            <hr>
            <div>
                <div style="display: inline-block">
                    <img id="goods-img" src="" alt=""
                         onerror="this.src='${baseUrl}images/noImg.jpg'">
                </div>
                <div style="display: inline-block;padding-left: 14px;">
                    <ul>
                        <li style="color: #aaaaaa;font-size: 12px;">支持jpg、jpeg、png</li>
                        <li style="color: #aaaaaa;font-size: 12px;">图片大小500KB以下</li>
                        <li style="color: #aaaaaa;font-size: 12px;">推荐分辨率600*600</li>
                    </ul>
                    <a class="layui-btn select-img">选择图片</a>
                </div>
            </div>

            <h3 class="mt10">基本信息</h3>
            <hr>
            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="no" readonly="readonly" autocomplete="off"  class="layui-input readonly" lay-verify="required|no">
                </div>
                <div class="layui-input-inline" style="padding-top: 10px">
                    <a href="javascript:;" class="reloadNo">重新加载</a>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" required lay-verify="required|name" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><span class="tip"></span></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">分类</label>
                <div class="layui-input-inline">
                    <select name="typeId" lay-verify="required|typeId"></select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">规格</label>
                <div class="layui-input-inline">
                    <input type="text" name="norms" placeholder="选填,如红色长款" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">基本单位</label>
                <div class="layui-input-inline">
                    <select name="unitId0" class="unitSelect"  lay-verify="required|unitId0"></select>
                    <input type="hidden" name="times0" value="1">
                </div>

                <div class="layui-input-inline">
                    <a class="layui-btn layui-btn-primary" id="add-unit">增加单位</a>
                </div>
            </div>
            <div id="second-unit-div"></div>

            <div class="layui-form-item">
                <label class="layui-form-label">多属性支持</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="moreAttr" title="" value="true" lay-skin="primary" lay-filter="moreAttr">
                </div>
            </div>

            <div id="attr-div" style="display: none;">
                <h3>属性</h3>
                <hr>
                <c:forEach items="${attrNameVoList}" var="attrNameVo" varStatus="status">
                    <div class="layui-form-item">
                        <label class="layui-form-label">${attrNameVo.name}</label>
                        <div class="layui-input-inline">
                            <select name="attr${status.index}" attrNameId="${attrNameVo.id}">
                                <option value=''>无</option>
                                <c:forEach items="${attrNameVo.attrList}" var="attr" >
                                    <option value='${attr.id}'>${attr.attrValue}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                </c:forEach>
            </div>

            <h3>其他</h3>
            <hr>
            <div class="layui-form-item">
                <label class="layui-form-label">商品状态</label>
                <div class="layui-input-inline">
                    <input type="radio" name="status" value="1" title="启用" checked>
                    <input type="radio" name="status" value="2" title="停用">
                </div>
            </div>

            <c:if test="${industryType.type eq 2}">
                <div class="layui-form-item">
                    <label class="layui-form-label">序列号</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="sn" value="true" title="启用" lay-filter="sn">
                        <input type="radio" name="sn" value="false" title="停用" lay-filter="sn" checked>
                    </div>
                </div>
            </c:if>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="remark" class="layui-textarea"></textarea>
                </div>
            </div>


            <h3>条形码</h3>
            <hr>
            <div id="code-div" style="overflow: auto"></div>

            <h3>价格</h3>
            <hr>
            <div id="price-div" style="overflow: auto"></div>

            <h3>
                期初库存<span class="font12 fontC999">（在启用本软件前仓库中已有的商品库存，录入期初库存可以使后续成本价、毛利等值的计算更准确；当商品被单据引用后无法修改初期信息，可以通过盘点来修正）</span>
            </h3>
            <hr>
            <div style="overflow: auto;">
                <table class="layui-table" style="min-width: 700px;">
                    <thead>
                    <th>门店</th>
                    <th>仓库</th>
                    <th>初期数量</th>
                    <th>初期成本</th>
                    <th>初期总额</th>
                    </thead>

                    <tbody>
                    <c:forEach items="${houseVoList}" var="houseVo" varStatus="status">
                        <tr id="${houseVo.id}" snList="[]" class="snList">
                            <td>${houseVo.store.name}</td>
                            <td>${houseVo.name}</td>
                            <td>
                                <div style="position: relative;">
                                    <input type='text' min="0" name='initNum${status.index}' initNumHouseId="${houseVo.id}" autocomplete="off" lay-verify="initNum"  class='layui-input pdr20 initNum'>
                                    <div style="position: absolute;top:8px;right: 6px;display: none;">
                                        <a class="sn-init-button layui-btn layui-btn-xs" style="background-color: #53606b" hid="${houseVo.id}">sn</a>
                                    </div>
                                </div>
                            </td>
                            <td><input type='text' name='initCost${status.index}' initCostHouseId="${houseVo.id}" autocomplete="off" lay-verify="positive"  class='layui-input initCost'></td>
                            <td><input type='text' name='initAmt${status.index}' initAmtHouseId="${houseVo.id}" autocomplete="off" lay-verify="positive"  class='layui-input initAmt'></td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>

            <h3>
                库存预警<span class="font12 fontC999">(当库存低于预警值时首页会显示对应的预警信息,多单位时按基本单位管理。)</span>
            </h3>
            <hr>
            <table class="layui-table" style="min-width: 700px;">
                <thead>
                <th>门店</th>
                <th>仓库</th>
                <th>最低库存量</th>
                <th>最高库存量</th>
                </thead>

                <tbody>
                <c:forEach items="${houseVoList}" var="houseVo" varStatus="status">
                    <tr>
                        <td>${houseVo.store.name}</td>
                        <td>${houseVo.name}</td>
                        <td><input type="text" name='minHouse${status.index}' class='layui-input minHouse' minHouseId="${houseVo.id}" autocomplete="off" lay-verify="positive"></td>
                        <td><input type="text" name='maxHouse${status.index}' class='layui-input maxHouse' maxHouseId="${houseVo.id}" autocomplete="off" lay-verify="positive"></td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </form>
    </div>
</div>
</body>

<script id="codeTable" type="text/html">
    <table class="layui-table" style="min-width: 700px;">
        <thead>
        <tr>
            <th style="text-align: center">名称</th>
            {{#  for(var i=0; i < parseInt(d.unitCount); i++){ }}
            {{#  var unitName = getUnitName(d['unitId'+i]); }}
            <th style="text-align: center">{{unitName}}</th>
            {{#  } }}
        </tr>
        </thead>
        <tbody>
        <td style="text-align: center">条形码</td>
        {{#  for(var i=0;i < parseInt(d.unitCount); i++){ }}
        {{#  var code = getCodeValue('code'+i); }}
        <td><input type='text' name='code{{i}}' value="{{code}}" class='layui-input code' onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"></td>
        {{#  } }}
        </tbody>
    </table>
</script>

<script id="priceTable" type="text/html">
    <table class="layui-table" style="min-width: 700px;">
        <thead>
        <tr>
            <th style="text-align: center">价格类别</th>
            {{#  for(var i=0; i < parseInt(d.unitCount); i++){ }}
            {{#  var unitName = getUnitName(d['unitId'+i]); }}
            <th style="text-align: center">价格/{{unitName}}</th>
            {{#  } }}
        </tr>
        </thead>

        <tbody>
        <tr>
            <td style="text-align: center">零售价</td>
            {{#  for(var i=0;i < parseInt(d.unitCount); i++){ }}
            {{#  var price = getValue(d['retailPrice'+i]); }}
            <td><input type="text" name='retailPrice{{i}}' value="{{price}}" class='layui-input retailPrice' autocomplete="off" lay-verify="positive"></td>
            {{#  } }}
        </tr>
        <tr>
            <td style="text-align: center">批发价</td>
            {{#  for(var i=0;i < parseInt(d.unitCount); i++){ }}
            {{#  var price = getValue(d['wholesalePrice'+i]); }}
            <td><input type="text" name='wholesalePrice{{i}}' value="{{price}}" class='layui-input wholesalePrice' autocomplete="off" lay-verify="positive"></td>
            {{#  } }}
        </tr>
        <tr>
            <td style="text-align: center">最低售价</td>
            {{#  for(var i=0;i < parseInt(d.unitCount); i++){ }}
            {{#  var price = getValue(d['minPrice'+i]); }}
            <td><input type="text" name='minPrice{{i}}' value="{{price}}" class='layui-input minPrice' autocomplete="off" lay-verify="positive"></td>
            {{#  } }}
        </tr>
        <tr>
            <td style="text-align: center">参考进货价</td>
            {{#  for(var i=0;i < parseInt(d.unitCount); i++){ }}
            {{#  var price = getValue(d['referBuyPrice'+i]); }}
            <td><input type="text" name='referBuyPrice{{i}}' value="{{price}}" class='layui-input referBuyPrice' autocomplete="off" lay-verify="positive"></td>
            {{#  } }}
        </tr>
        </tbody>
    </table>
</script>

<script id="second_unit" type="text/html">
    <div class="layui-form-item">
        <label class="layui-form-label">
            <i class='layui-icon layui-icon-delete deleteSecondUnit' style='color: #FF5722'></i><span>副单位{{d.unitCount}}</span>
        </label>
        <div class="layui-input-inline">
            <select name="unitId{{d.unitCount}}" class="unitSelect"  lay-verify="required|unitId{{d.unitCount}}">
                {{#  layui.each(getUnitList(), function(i, d){ }}
                <option value="{{d.id}}">{{d.name}}</option>
                {{#  }); }}
            </select>
        </div>
        <div class="layui-form-mid">=</div>
        <div class="layui-input-inline">
            <input type="text" name="times{{d.unitCount}}" placeholder="换算倍数" autocomplete="off" lay-verify="times" class="layui-input times">
        </div>

        <div class="layui-form-mid baseUnitName">{{getUnitName(d.unitId0)}}</div>
    </div>
</script>

<script id="init_unit" type="text/html">
    {{# for(var i=1 ;i < d.length ; i++){ }}
    {{#     let goodsUnit = d[i]; }}
    <div class="layui-form-item">
        <label class="layui-form-label">
            <i class='layui-icon layui-icon-delete deleteSecondUnit' style='color: #FF5722'></i><span>副单位{{i}}</span>
        </label>
        <div class="layui-input-inline">
            <select name="unitId{{i}}" class="unitSelect"  lay-verify="required|unitId{{i}}">
                {{#  layui.each(getUnitList(), function(i, unit){ }}
                <option value="{{unit.id}}">{{unit.name}}</option>
                {{#  }); }}
            </select>
        </div>
        <div class="layui-form-mid">=</div>
        <div class="layui-input-inline">
            <input type="text" name="times{{i}}" placeholder="换算倍数" autocomplete="off" lay-verify="times" class="layui-input times">
        </div>

        <div class="layui-form-mid baseUnitName">{{getUnitName(d[0].unitId)}}</div>
    </div>

    {{# } }}
</script>
<html:loading tip="商品更新中,请勿关闭网页"/>
</html>